package minidb.test;

import static minidb.type.Const.dbFile;
import static minidb.type.Const.tablePage;
import java.io.IOException;
import minidb.file.FileMgr;
import minidb.record.TablePage;

class thread1 extends Thread{
	OverAllTest test;
	public thread1(OverAllTest test){
		this.test = test;
	}
	
	public void run(){
		for(int i=6;i<100;i+=3){
			test.DoStr(String.format("insert into table1 (id,name,info) values"
					+"(%d,'wangurey%d','info%d')",i,i,i));
			System.err.println(Thread.currentThread().getId());
		}
	}
}
class thread2 extends Thread{
	OverAllTest test;
	public thread2(OverAllTest test){
		this.test = test;
	}
	
	public void run(){
		for(int i=5;i<100;i+=3){
			test.DoStr(String.format("insert into table1 (id,name,info) values"
					+"(%d,'wangurey%d','info%d')",i,i,i));
			System.err.println(Thread.currentThread().getId());
		}
	}
}
class thread3 extends Thread{
	OverAllTest test;
	public thread3(OverAllTest test){
		this.test = test;
	}
	
	public void run(){
		for(int i=4;i<100;i+=3){
			test.DoStr(String.format("insert into table1 (id,name,info) values"
					+"(%d,'wangurey%d','info%d')",i,i,i));
			System.err.println(Thread.currentThread().getId());
		}
	}
}

class thread4 extends Thread{
	OverAllTest test;
	public thread4(OverAllTest test){
		this.test = test;
	}
	
	public void run(){
		try {
			while(true){
				this.sleep(300);
				test.DoStr("select * from table1");
				System.err.println(Thread.currentThread().getId());
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
public class test2 {


	public static void main(String argv[]) throws IOException, ClassNotFoundException{
		
		FileMgr fMgr = new FileMgr("d:\\a.zcx");
		dbFile(fMgr);
		TablePage table = new TablePage();
		tablePage(table);
		OverAllTest test =  new OverAllTest();
		test.DoStr("create table table1(id integer, name char(10), info char(10))");
		new thread1(test).start();
		new thread2(test).start();
		new thread3(test).start();
		new thread4(test).start();
		while(true){
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.err.println(Thread.currentThread().getId());
		}
	}
}
